﻿using System;
using System.Linq;
using System.Web.Mvc;
using BLL;
using Model;
using System.Data.Objects.SqlClient;


namespace Web.Areas.Manager.Controllers
{
    [NoCache]
    [HandleError]
    [UserAuthorize]
    public class jqGridTestController : Controller
    {
        Sys_Users_Logs_BLL _Sys_Users_Logs_BLL = new Sys_Users_Logs_BLL();

        public virtual ActionResult Index(int? pageIndex, string keyword)
        {
            return View();
        }

        public JsonResult Edit(string sidx, string sord, int page, int rows)
        {
            var context = _Sys_Users_Logs_BLL.Get();
         
     
            int pageIndex = Convert.ToInt32(page) - 1;
       
            int pageSize = rows;
            int totalRecords = context.Count();
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            var questions = context.Skip(pageIndex * pageSize).Take(pageSize);


            var jsonData = new
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                from t in questions
                select new
                {

                    cell = new 
                    {
                        t.IP,
                        t.Content
                    }
                }).ToArray()
            };

            return Json(jsonData, JsonRequestBehavior.AllowGet);

        }

    }
}
